<script lang="ts" setup name="AdjustmentOrder">
import { CirclePlus, Delete, EditPen } from '@element-plus/icons-vue'
import { ProTableInstance } from '~/library/components/ProTable/interface'
import { Procure } from '~/src/api/interface/procure'
import { deleteWareHouseAPI, getRejectionListAPI, unCheckWareHouseAPI } from '~/src/api/procure'
import { adjustmentOrderColumn } from './info/columns'
const proTableRef = ref<ProTableInstance>()
const initParam = reactive({ orderType: 2 })
const router = useRouter()
const toCreate = (data?: Procure.Rejection) => {
  if (data) {
    // 判断状态是是什么查看还是编辑
    router.push('/procure/adjustmentOrderEdit?type=' + (data.checkFlag ? 'view' : 'edit') + '&orderNo=' + data.id)
  } else {
    router.push('/procure/adjustmentOrderEdit?type=add')
  }
}
const onDelete = async (row: Procure.Rejection) => {
  await useHandleData(deleteWareHouseAPI, { id: row.id }, `删除编号【${row.orderNo}】库存调整单`)
  proTableRef.value?.getTableList()
}
const onCancelRow = async (row: Procure.Rejection) => {
  await useHandleData(unCheckWareHouseAPI, { id: row.id }, `反审核编号【${row.orderNo}】库存调整单`)
  proTableRef.value?.getTableList()
}
</script>

<template>
  <div class="auto-height-container">
    <pro-table
      ref="proTableRef"
      :columns="adjustmentOrderColumn"
      highlight-current-row
      :indent="20"
      :init-param="initParam"
      :isCard="false"
      :pagination="true"
      :request-api="getRejectionListAPI"
      row-key="id"
      title="库存调整列表"
    >
      <template #tableHeader>
        <el-button v-auth="'add'" :icon="CirclePlus" type="primary" @click="toCreate()">新增库存调整</el-button>
      </template>
      <template #orderNo="{ row }">
        <el-button v-auth="'edit'" :icon="EditPen" link type="primary" @click="toCreate(row)">
          {{ row.orderNo }}
        </el-button>
      </template>
      <template #operation="scope">
        <el-button v-if="!scope.row.checkFlag" v-auth="'delete'" :icon="Delete" link type="primary" @click="onDelete(scope.row)">
          删除
        </el-button>
        <el-button v-if="scope.row.checkFlag" v-auth="'cancel'" :icon="Delete" link type="primary" @click="onCancelRow(scope.row)">
          反审核
        </el-button>
      </template>
    </pro-table>
  </div>
</template>

<style lang="scss" scoped></style>
